package com.zxq.web.channel;

import com.zxq.exchange.enums.EFrame;
import com.zxq.exchange.model.ExchangeDTO;
import com.zxq.exchange.register.INotifyPlatform;
import com.zxq.exchange.register.NotifyPlatformRegister;
import com.zxq.web.notifyplatfrom.NotifyPlatformFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
@Slf4j
public class TcpMessageChannel implements INotifyPlatform {

    @PostConstruct
    public void initRegister() {
        NotifyPlatformRegister.getInstance(EFrame.modbus).registerNotify(this);
        NotifyPlatformRegister.getInstance(EFrame.dlt645).registerNotify(this);
        NotifyPlatformRegister.getInstance(EFrame.jt808).registerNotify(this);
        NotifyPlatformRegister.getInstance(EFrame.fy_charge_pile).registerNotify(this);
        NotifyPlatformRegister.getInstance(EFrame.sf_register).registerNotify(this);
    }

    @Autowired
    NotifyPlatformFactory notifyPlatformFactory;



    @Override
    public void notifyPlatform(ExchangeDTO exchangeDTO) {
       notifyPlatformFactory.create(exchangeDTO.getFrame()).notifyPlatform(exchangeDTO);
    }


}
